package org.tinaelle.client.gui.tree;

import com.gwtext.client.data.ArrayReader;
import com.gwtext.client.data.FieldDef;
import com.gwtext.client.data.IntegerFieldDef;
import com.gwtext.client.data.MemoryProxy;
import com.gwtext.client.data.RecordDef;
import com.gwtext.client.data.Store;
import com.gwtext.client.data.StringFieldDef;

public class TreeManager {
	private static Store	   treeStore;
	private static ArrayReader	treeReader;
	private static MemoryProxy	treeProxy;

	private static Store	   treeNodeStore;
	private static ArrayReader	treeNodeReader;
	private static MemoryProxy	treeNodeProxy;

	public TreeManager() {

	}

	public Store getTreeStore() {
		if ( treeStore == null ) {
			treeProxy = new MemoryProxy( getTreeData() );

			final RecordDef recordDef = new RecordDef( new FieldDef[] {
			        new IntegerFieldDef( "adTreeId" ),
			        new StringFieldDef( "name" ),
			        new StringFieldDef( "description" ),
			        new StringFieldDef( "type" ) } );

			treeReader = new ArrayReader( 0, recordDef );
			treeStore = new Store( treeProxy, treeReader );
			treeStore.load();
		}
		return treeStore;
	}

	public ArrayReader getTreeReader() {
		getTreeStore();
		return treeReader;
	}

	public MemoryProxy getTreeProxy() {
		getTreeStore();
		return treeProxy;
	}

	public Store getTreeNodeStore() {
		if ( treeNodeStore == null ) {
			treeProxy = new MemoryProxy( getTreeNodeData() );

			final RecordDef recordDef = new RecordDef( new FieldDef[] {
			        new IntegerFieldDef( "adTreeNodeId" ),
			        new StringFieldDef( "title" ),
			        new StringFieldDef( "tooltip" ),
			        new StringFieldDef( "iconCls" ),
			        new StringFieldDef( "thumbnail" ),
			        new IntegerFieldDef( "parentId" ),
			        new IntegerFieldDef( "seqNo" ),
			        new IntegerFieldDef( "adScreenId" ),
			        new IntegerFieldDef( "adTableId" ),
			        new IntegerFieldDef( "adTreeId" ) } );

			treeNodeReader = new ArrayReader( 0, recordDef );
			treeNodeStore = new Store( treeNodeProxy, treeNodeReader );
			treeNodeStore.load();
		}
		return treeStore;
	}

	public ArrayReader getTreeNodeReader() {
		getTreeNodeStore();
		return treeNodeReader;
	}

	public MemoryProxy getTreeNodeProxy() {
		getTreeNodeStore();
		return treeNodeProxy;
	}

	public Object[][] getTreeData() {

		return null;
	}

	public Object[][] getTreeNodeData() {

		return null;
	}
}
